home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Include / FWArDyna.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  8.4 KB  |  219 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWArDyna.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWARDYNA_H
  11. #define FWARDYNA_H
  12.  
  13. #ifndef FWTMAP_H
  14. #include "FWTMap.h"
  15. #endif
  16.  
  17. #ifndef FWCLAINF_H
  18. #include "FWClaInf.h"
  19. #endif
  20.  
  21. #ifndef FWSTRMRW_H
  22. #include "FWStrmRW.h"
  23. #endif
  24.  
  25. #ifndef FWSTDDEF_H
  26. #include "FWStdDef.h"
  27. #endif
  28.  
  29. #include "SLObjReg.xh"
  30.  
  31. //========================================================================================
  32. // Typedefs and constants
  33. //========================================================================================
  34.  
  35. typedef unsigned long FW_ClassTypeConstant;
  36. const FW_ClassTypeConstant FW_kPrivByteMask = 0x0FFUL;
  37.  
  38. //========================================================================================
  39. // MACROS
  40. //========================================================================================
  41.  
  42. #define FW_PRIV_BYTE(a, i) ((FW_ClassTypeConstant(a)&FW_kPrivByteMask)<<(8*i))
  43. #define FW_TYPE_CONSTANT(a,b,c,d) (FW_PRIV_BYTE(a, 3) + FW_PRIV_BYTE(b, 2) + FW_PRIV_BYTE(c, 1) + FW_PRIV_BYTE(d, 0))
  44.  
  45. const FW_ClassTypeConstant FW_kNullTypeConstant = FW_TYPE_CONSTANT('n', 'u', 'l', 'l');
  46. const FW_ClassTypeConstant FW_kWildCardLabel = FW_TYPE_CONSTANT('w', 'i', 'l', 'd');
  47.  
  48. //----------------------------------------------------------------------------------------
  49. // FW_REGISTER_ARCHIVABLE_CLASS
  50. //----------------------------------------------------------------------------------------
  51.  
  52. #define FW_REGISTER_ARCHIVABLE_CLASS(classLabel, classType, create, initialize, destroy, output) \
  53.     extern void FW_DoNotDeadStrip##classType(); \
  54.     void FW_DoNotDeadStrip##classType() {} \
  55.     FW_CPrivArchiver FWArchive##classLabel(classLabel, \
  56.                                         FW_CLASSNAME_FROM_TYPE(classType), \
  57.                                         FW_SPrivArcFun(create, initialize, destroy, output));
  58.  
  59. //----------------------------------------------------------------------------------------
  60. // FW_REGISTER_ARCHIVABLE_SOM_CLASS
  61. //----------------------------------------------------------------------------------------
  62.  
  63. #define FW_REGISTER_ARCHIVABLE_SOM_CLASS(classLabel, classType, create, initialize, destroy, output) \
  64.     FW_CPrivArchiver FWArchive##classLabel(classLabel, \
  65.                                         classType##NewClass(0,0)->somGetName(), \
  66.                                         FW_SPrivArcFun(create, initialize, destroy, output));
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS
  70. //----------------------------------------------------------------------------------------
  71.  
  72. #define FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS(oldVersionClassLabel, create, initialize, destroy) \
  73.     FW_CPrivArchiver FWArchive##oldVersionClassLabel(oldVersionClassLabel, \
  74.                                         FW_SPrivArcFun(create, initialize, destroy, 0));
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //     FW_DO_NOT_DEAD_STRIP
  78. //----------------------------------------------------------------------------------------
  79.  
  80. #define FW_DO_NOT_DEAD_STRIP(classType) \
  81.     extern void FW_DoNotDeadStrip##classType(); \
  82.     FW_DoNotDeadStrip##classType();
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //     FW_PREREGISTER_RUNTIME_OBJECT
  86. //----------------------------------------------------------------------------------------
  87.  
  88. #define FW_PREREGISTER_RUNTIME_OBJECT(stream, object, objectID) \
  89.     FW_CPrivArchiver::PreregisterSpecialObject(stream, object, objectID)
  90.  
  91. //========================================================================================
  92. // Forward Declarations
  93. //========================================================================================
  94.  
  95. struct FW_SPrivArchiverGlobals;
  96.  
  97. //========================================================================================
  98. //    Struct FW_SPrivArcStr
  99. //    An internal implementation class used in maps for string-type keys and values
  100. //========================================================================================
  101.  
  102. struct FW_SPrivArcStr
  103. {
  104. public:
  105.     FW_SPrivArcStr() : fString(NULL) {}
  106.     FW_SPrivArcStr(const char* string);
  107.     const char* fString;
  108. };
  109.  
  110. //========================================================================================
  111. //    Struct FW_SPrivArcFun
  112. //    An internal implementation class used in maps for I/O function pointer values
  113. //========================================================================================
  114.  
  115. struct FW_SPrivArcFun
  116. {
  117.     typedef void* (*Create)(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  118.     typedef void (*Initialize)(FW_CReadableStream& stream, FW_ClassTypeConstant type, void* object);
  119.     typedef void (*Destroy)(void* object, FW_ClassTypeConstant type);
  120.     typedef void (*Output)(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  121.  
  122.     FW_SPrivArcFun() {}
  123.     FW_SPrivArcFun(Create create,
  124.                    Initialize initialize,
  125.                    Destroy destroy,
  126.                    Output output);
  127.     Create fCreateFunction;
  128.     Initialize fInitializeFunction;
  129.     Destroy fDestroyFunction;
  130.     Output fOutputFunction;
  131. };
  132.  
  133. //========================================================================================
  134. // FW_CPrivNameToLabelMap/FW_CPrivLabelToIOFunctionMap
  135. //========================================================================================
  136.  
  137. typedef FW_TMap<FW_SPrivArcStr, FW_ClassTypeConstant> FW_CPrivNameToLabelMap;
  138. typedef FW_TMap<FW_ClassTypeConstant, FW_SPrivArcFun> FW_CPrivLabelToIOFunctionMap;
  139. typedef FW_TPair<FW_SPrivArcStr, FW_ClassTypeConstant> FW_CPrivNameToLabelPair;
  140. typedef FW_TPair<FW_ClassTypeConstant, FW_SPrivArcFun> FW_CPrivLabelToIOFunctionPair;
  141.  
  142. //========================================================================================
  143. // STRUCT FW_SPrivArchiverGlobals
  144. //========================================================================================
  145.  
  146. struct FW_SPrivArchiverGlobals
  147. {
  148.     FW_CPrivNameToLabelMap*         gNameToLabelMap;
  149.     FW_CPrivLabelToIOFunctionMap*     gLabelToIOFunctionMap;
  150. };
  151.  
  152. //========================================================================================
  153. //    Class FW_CPrivArchiver
  154. //========================================================================================
  155.  
  156. class FW_CPrivArchiver
  157. {
  158. public:
  159.  
  160.     static void CreateObject(FW_CReadableStream& readableStream, void*& object);
  161.         // Input an object of a dynamic class from the readableStream.
  162.  
  163.     static void OutputObject(FW_CWritableStream& writableStream,
  164.                              const void* object,
  165.                              const char* className);
  166.         // Output an object of a dynamic class to the writableStream.
  167.  
  168.     static void* PrivCreateObject(FW_CReadableStream& readableStream,
  169.                                 FW_ClassTypeConstant classLabel); 
  170.         // Reads object data for static and dynamic classes from the readableStream.
  171.  
  172.     static void PrivOutputObject(FW_CWritableStream& writableStream, 
  173.                                 FW_ClassTypeConstant classLabel, 
  174.                                 const void* object);
  175.         // Writes object data for static and dynamic classes to the writableStream.
  176.  
  177.     static void PreregisterSpecialObject(FW_CReadableStream& readableStream,
  178.                                     const void* object,
  179.                                     FW_ObjectRegistry_ID objectID);
  180. public:
  181.  
  182.     static void Initialize(FW_SPrivArchiverGlobals& globals);
  183.     static void Terminate();
  184.     static FW_SPrivArchiverGlobals& GetArchiverGlobals();
  185.  
  186. public:
  187.  
  188.     FW_CPrivArchiver(FW_ClassTypeConstant classLabel,
  189.                         const char* className,
  190.                         const FW_SPrivArcFun& functions);
  191.         // Register the <classLabel, className, archiving functions> triple with the archiver
  192.  
  193.     FW_CPrivArchiver(FW_ClassTypeConstant classLabel,
  194.                         const FW_SPrivArcFun& functions);
  195.         // Register the <classLabel, archiving functions> pair with the archiver
  196.         // This constructor is use for a "previous version" label.  The className
  197.         // is therefore unnecessary.
  198.  
  199.     static FW_CPrivLabelToIOFunctionPair* LookupArchivingFunctions(FW_ClassTypeConstant classLabel);
  200.     
  201. private:
  202.  
  203.     static FW_CPrivNameToLabelMap& GetNameToLabelMap();
  204.     static FW_CPrivLabelToIOFunctionMap& GetLabelToIOFunctionMap();
  205.     
  206.     static void AddNameToLabelPair(FW_ClassTypeConstant classLabel, const char* className);
  207.     static void AddLabelToIOFunctionPair(FW_ClassTypeConstant classLabel, const FW_SPrivArcFun& functions);
  208.  
  209. private:
  210.     static FW_SPrivArchiverGlobals gGlobals;
  211.  
  212. private:
  213.     FW_CPrivArchiver(const FW_CPrivArchiver& archiver);
  214.     FW_CPrivArchiver& operator=(const FW_CPrivArchiver& archiver);
  215.         // Shouldn't need to copy this class.
  216. };
  217.  
  218. #endif
  219.